﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using SweetSurvey.Models;
using SweetSurvey.Models.Repositories;

namespace SweetSurvey.Tests.RepositoryTests
{
    /// <summary>
    ///This is a test class for EditorRepositoryTest and is intended
    ///to contain all EditorRepositoryTest Unit Tests
    ///</summary>
    [TestClass]
    public class EditorRepositoryTest : RepositoryTestBase
    {
        #region Create Sample Data

        public static string CreateSampleEditor()
        {
            return (new EditorRepository()).CreateTemporaryEditor();
        }

        #endregion

        /// <summary>
        ///A test for CreateTemporaryEditor
        ///</summary>
        [TestMethod]
        public void CreateTemporaryEditorTest()
        {
            // prepare
            var editorRepository = new EditorRepository();
            
            // act
            var editorId = editorRepository.CreateTemporaryEditor();
            
            // assert
            Assert.IsFalse(string.IsNullOrEmpty(editorId));
            Editor editor = editorRepository.Get(editorId);
            Assert.IsNotNull(editor);
        }

        /// <summary>
        ///A test for Update
        ///</summary>
        [TestMethod]
        public void UpdateTest()
        {
            // prepare
            var id = EditorRepositoryTest.CreateSampleEditor();
            var repository = new EditorRepository();
            var editor = repository.Get(id);

            // act
            repository.Update(editor);

            // assert (no error)
        }
    }
}
